package clases;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


public class Main 
{
	public static void main(String[] args) throws IOException, ClassNotFoundException
	{
		Persona p1 = new Persona("Pepe", "28655654", 32);
		Persona p2 = new Persona("Alicia", "32251251", 28);
		Persona p3 = new Persona("Alberto", "17852584", 51);
		
		try {
			FileOutputStream fos;
			fos = new FileOutputStream("personas2014.txt");
			ObjectOutputStream out = new ObjectOutputStream(fos);
			out.writeObject(p1);
			out.writeObject(p2);
			out.writeObject(p3);
			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		Padron miPadron = new Padron();
		miPadron.agregar(p1);
		miPadron.agregar(p2);
		miPadron.agregar(p3);
		
		System.out.println(miPadron.toString());

		try {
			FileOutputStream fos;
			fos = new FileOutputStream("padron.txt");
			ObjectOutputStream out = new ObjectOutputStream(fos);
			out.writeObject(miPadron);
			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		Persona lp=null;
		try {
			FileInputStream fis;
			fis = new FileInputStream("personas2014.txt");
			ObjectInputStream in = new ObjectInputStream(fis);
			lp = (Persona) in.readObject();
			fis.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		System.out.println(lp.toString());
		
		
	}

}
